const Admin = require('./admin'),
      User = require('./user')
      Problem = require('./problem'),
      ProblemType = require('./problem_type'),
      ProblemAnswer = require('./problem_answer'),
      DataTable = require('./data_table'),
      
      ResolveRecord = require('./resolve_record'),
      ResolveList = require('./resolve_list'),
      LoginInfo = require('./login_info'),
      
      RecommendList = require('./recommend_list'),
      RecommendWeightBase = require('./recommend_weight_base'),
      RecommendWeightAdvance = require('./recommend_weight_advance');


//定义模型关系

//用户
User.hasMany(ResolveRecord);
ResolveRecord.belongsTo(User, { constraints: true, onDelete: 'CASCADE'});  //一个用户有多条记录，一条记录对应一个用户; 一堆多，一对一

User.hasOne(ResolveList);
ResolveList.belongsTo(User, { constraints: true, onDelete: 'CASCADE'}); //一个用户有一个历史做题列表; 一对一，一对一

User.hasMany(LoginInfo);
LoginInfo.belongsTo(User, { constraints: true, onDelete: 'CASCADE'}); //一个用户有多条登录信息，每条登录信息对应一个用户； 一对多，一对一

User.hasMany(RecommendList);
RecommendList.belongsTo(User, { constraints: true, onDelete: 'CASCADE'}); //一个用户有多条推荐列表，一个列表对应一个用户; 一对多，一对一

User.hasOne(RecommendWeightBase);
RecommendWeightBase.belongsTo(User, { constraints: true, onDelete: 'CASCADE'}); //基础类型权重，一对一，一对一

User.hasOne(RecommendWeightAdvance);
RecommendWeightAdvance.belongsTo(User, { constraints: true, onDelete: 'CASCADE'}); //进阶类型权

//题目
Problem.hasMany(ProblemAnswer); //一个题目有多个解答，
ProblemAnswer.belongsTo(Problem, { constraints: true, onDelete: 'CASCADE'}); //一个解答属于一个题目

Problem.hasMany(ResolveRecord); //一个题目有多条记录
ResolveRecord.belongsTo(Problem, { constraints: true, onDelete: 'CASCADE'}); //一条记录属于一个问题

//题目类型
ProblemType.hasMany(Problem);  //一个题目类型包含多个题目
Problem.belongsTo(ProblemType, { constraints: true, onDelete: 'CASCADE'}); //一个题目属于一个类型

ProblemType.hasMany(ResolveRecord);  //一个题目类型包含多个做题记录
ResolveRecord.belongsTo(ProblemType, { constraints: true, onDelete: 'CASCADE' }); //一个做题记录属于一个题目

//类型表
// Problem.hasMany(ProblemAnswer);
// ProblemAnswer.belongsTo(Problem, { constraints: true, onDelete: 'CASCADE'});

module.exports = {
  Admin,
  User,
  Problem,
  ProblemType,
  ProblemAnswer,
  ResolveRecord,
  ResolveList,
  LoginInfo,
  RecommendList,
  RecommendWeightBase,
  RecommendWeightAdvance,
  DataTable
}